//
//  FLLRelatedDishViewController.m
//  FLLGodOfCooking
//
//  Created by LL.F on 16/9/16.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLRelatedDishViewController.h"
#import "FLLMacro.h"
#import "FLLInfoTableViewCell.h"
#import "FLLRelatedDishTableViewCell.h"
#import "FLLMakeFoodViewController.h"

@interface FLLRelatedDishViewController ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation FLLRelatedDishViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createRelatedDishTableView];
    
    
}
- (void)createRelatedDishTableView
{
    
    self.relatedDishTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 115 * kHeightScale) style:UITableViewStylePlain];
    self.relatedDishTableView.delegate = self;
    self.relatedDishTableView.dataSource = self;
   
    self.relatedDishTableView.bounces = NO;
    [self.relatedDishTableView registerNib:[UINib nibWithNibName:@"FLLRelatedDishTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"relatedDishTableCell"];
  
    [self.view addSubview:_relatedDishTableView];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  
    return _relatedDishArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    FLLRelatedDishTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"relatedDishTableCell"];
    cell.titleLabel.text = _relatedDishArray[indexPath.row].title;
    cell.contentLabel.text = _relatedDishArray[indexPath.row].description_Data;
    cell.levelLabel.text = [NSString stringWithFormat:@"难易度:%@", _relatedDishArray[indexPath.row].hard_level];
    cell.tasteLabel.text = [NSString stringWithFormat:@"口味: %@", _relatedDishArray[indexPath.row].taste];
    cell.timeLabel.text = [NSString stringWithFormat:@"烹饪时间: %@", _relatedDishArray[indexPath.row].cooking_time];
    
    
    cell.titleLabel.font = [UIFont systemFontOfSize:15 * kWidthScale];
    cell.contentLabel.font = [UIFont systemFontOfSize:13 *kWidthScale];
    cell.contentLabel.numberOfLines = 2;
    cell.levelLabel.font = [UIFont systemFontOfSize:12 * kWidthScale];
    cell.tasteLabel.font = [UIFont systemFontOfSize:12 * kWidthScale];
    cell.timeLabel.font = [UIFont systemFontOfSize:12 * kWidthScale];
    
    [cell.dishImageView sd_setImageWithURL:[NSURL URLWithString:_relatedDishArray[indexPath.row].image] placeholderImage:[UIImage new] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
    
    return cell;
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    return SCREEN_WIDTH * 0.4;
    
}

- (void)setRelatedDishArray:(NSMutableArray<RelatedDishSecData *> *)relatedDishArray
{

    _relatedDishArray = relatedDishArray;
    [self.relatedDishTableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *idString = _relatedDishArray[indexPath.row].dishes_id;
    FLLMakeFoodViewController *makeFoodVC = [[FLLMakeFoodViewController alloc] init];
    [self.navigationController pushViewController:makeFoodVC animated:YES];
    makeFoodVC.idString = idString;

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
